package com.woniuxy.mesboot.controller;

import com.woniuxy.mesboot.entity.SysDept;
import com.woniuxy.mesboot.service.DeptService;
import com.woniuxy.mesboot.util.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author ：lisir
 * @date ：Created in 2023/5/27 11:35
 * @description：TODO
 */
@RestController
@RequestMapping("/depts")
@Slf4j
public class DeptController {

    @Resource
    private DeptService deptService;

    @PostMapping
    public Result add(@RequestBody SysDept dept) {
        deptService.insertSelective(dept);
        return Result.ok();
    }

    @DeleteMapping("{id}")
    public Result delete(@PathVariable Long id) {
        deptService.deleteByPrimaryKey(id);
        return Result.ok();
    }

    @PutMapping
    public Result update(@RequestBody SysDept dept) {
        deptService.updateByPrimaryKeySelective(dept);
        return Result.ok();
    }

    @GetMapping("{id}")
    public Result queryById(@PathVariable Long id) {
        SysDept dept = deptService.selectByPrimaryKey(id);
        if (dept != null) {
            return Result.ok().data("empJob",dept);
        } else {
            return Result.error("暂无数据");
        }
    }

    @GetMapping
    public Result queryAll() {
        List<SysDept> depts = deptService.selectAll();
        return Result.ok().data("list",depts);
    }

}
